package com.yinquan.util;

import java.util.Random;

import com.yishun.springboot.dao.CWRServiceTest;

import lombok.extern.slf4j.Slf4j;

/**
 * 获取随机字符串类
 * 
 * @author YS
 *
 */

@Slf4j
public class GetNumber {

	public static String getScopeNumber(int start, int end) {
		Integer num = (int) (Math.random() * (end - start + 1)) + start;
		if (num < 10)
			return "0" + num;
		return String.valueOf(num);
	}

	/**
	 * 获取24位大写字母以及24位小写字母以及0-9的随机字符串
	 * 
	 * @param length
	 * @return
	 */
	// length用户要求产生字符串的长度
	public static String getRandomNumberAndLetterString(int length) {
		String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			int number = random.nextInt(62);
			sb.append(str.charAt(number));
		}
		return sb.toString();
	}

	// 后续改良成专门生成为uid的方法，从数据库查询出来对应uid，对比以及存在则重新生成
	public static String getRandomNumberString(int length) {
		String str = "0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();

		for (int i = 0; i < length; i++) {
			int number = random.nextInt(10);
			sb.append(str.charAt(number));
		}
		return sb.toString();
	}

	public static void main(String[] args) {
		String a = "pinyi1" + getRandomNumberString(5);
		log.info(a);
	}
}
